<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let str = `2022-12-20`;

      /*
        1 写出正则表达式
        2 给正则表达式各部分使用括号包裹
      */
      console.log(str.match(/^(\d{4}-\d{2})-(\d{2})$/));
      console.log(str.match(/^(\d{4})-(\d{2}-\d{2})$/));
      console.log(str.match(/^(\d{4})-((\d{2})-(\d{2}))$/));
    </script>
  </body>
</html>
